package think.bank;

import java.util.HashMap;
import java.util.Map;

public class Bank {
	private static Bank bank;
	
	public static final String BANK_NAME = "中国建设银行";
	public static final String BANK_EN_NAME = "CCB";
	
	//组合
	private  Map<String,IndividualAccount> account = new HashMap<>();
	
	//单例
	private Bank(){}
	public static Bank getInstance(){
		if(bank ==null){
			bank = new Bank();
		}
		return bank;
	}
	
	public boolean createAccount(IndividualAccount account){
		this.account.put(account.getAccountName(), account);
		return true;
	}
	public boolean saveMoney(IndividualAccount account,int money){
		return account.saveMoney(money);
	}
	
	public Map<String,IndividualAccount> getAccount(){
		return account;
	}
	
	/**
	 * 取钱方法
	 * @param accountName
	 * @param money
	 * @return
	 */
	public boolean getMoney(String accountName,int money){
		IndividualAccount iAccount = account.get(accountName);
		return getMoney(iAccount,money);
	}
	
	public boolean getMoney(IndividualAccount account ,int money){
		return account.getMoney(money);
	}
	
	public boolean getMoneyThread(IndividualAccount account ,int money){
		return account.getMoneyThread(money);
	}
	
}
